//
//  ProgressView.m
//  Project two framework
//
//  Created by rimi on 16/7/28.
//  Copyright © 2016年 张峥. All rights reserved.
//

#import "ProgressView.h"
#import "ZZConfig.h"
#import "ProgressTableViewCell.h"
#import "ProgressViewController.h"
#import "ZPZNetRequest+getClientList.h"
@interface ProgressView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UILabel *name;
/** 订单号 */
@property (nonatomic, strong) UILabel *orderID;

@property (nonatomic, strong) ProgressViewController *progressController;
@end

@implementation ProgressView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self interface];
    }
    return self;
}

- (void)interface
{
    [self addSubview:self.imageView];
    [self.imageView addSubview:self.name];
    [self.imageView addSubview:self.orderID];
    [self.imageView addSubview:self.back];
    [self.imageView addSubview:self.tableView];
    
}
#pragma mark - 网络请求
- (void)loadDataSource
{
    _dataSource = [NSMutableArray array];
    [ZPZNetRequest getOrderProgressKeywords:self.keyword PageSize:@"20" UserId:@"22" PageNum:@"1" comletion:^(id object, BOOL success) {
        if (success) {
            [_dataSource addObjectsFromArray:object[@"content"]];
            [self.tableView reloadData];
        }
    }];
}
#pragma mark - 按钮的实现
//- (void)backAction:(UIButton *)sender
//{
//    ProgressViewController *PVC = [ProgressViewController new];
//    [UIView animateWithDuration:0.5 animations:^{
//        [PVC.scrollView setContentOffset:CGPointMake(0, 0)];
//    }];
//    
//}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    ProgressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[ProgressTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellEditingStyleNone;
    cell.name.text = _dataSource[indexPath.row][@"purchaser"];
    cell.productID.text = _dataSource[indexPath.row][@"order"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = @{@"status":_dataSource[indexPath.row][@"serviceStatus"]};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"notification" object:nil userInfo:dic];
}

#pragma mark - 懒加载

-(UIImageView *)imageView
{
    if (_imageView == nil) {
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, SCREEN_WIDTH - 120, SCREEN_HEIGHT - 120)];
        _imageView.userInteractionEnabled = YES;
        _imageView.image = [UIImage imageNamed:@"down_05.png"];
    }
    return _imageView;
}

- (UILabel *)name
{
    if (_name == nil) {
        _name = [[UILabel alloc]initWithFrame:CGRectMake(35, 145, 350, 25)];
        _name.text = @"姓名";
        _name.textAlignment = NSTextAlignmentCenter;
        _name.textColor = [UIColor whiteColor];
        _name.font = [UIFont systemFontOfSize:25];
    }
    return _name;
}

- (UILabel *)orderID
{
    if (_orderID == nil) {
        _orderID = [[UILabel alloc]initWithFrame:CGRectMake(385, 145, 200, 25)];
        _orderID.text = @"订单号";
        _orderID.textAlignment = NSTextAlignmentCenter;
        _orderID.textColor = [UIColor whiteColor];
        _orderID.font = [UIFont systemFontOfSize:25];
        
    }
    return _orderID;
}



- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(35, 170, CGRectGetWidth(self.imageView.bounds) - 70, 225)];
        _tableView.rowHeight = 95;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (UIButton *)back
{
    if (_back == nil) {
        _back = [UIButton buttonWithType:UIButtonTypeCustom];
        _back.frame = CGRectMake(380, 500, 160, 50);
        [_back setImage:[UIImage imageNamed:@"返回.png"] forState:UIControlStateNormal];
        
        
    }
    return _back;
}























































@end
